﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Collections.Generic;
using PsychSurvey.Properties;

namespace PsychSurvey.Participant
{
    public partial class Study : System.Web.UI.Page
    {
        public static string StudyQueryString = "Study";
        public static string DevelopmentQueryString = "Test";
        public static string SessionInitializationKey = "sik";
        private Guid _StudyGuid = Guid.Empty;
        private bool _isDevelopment = false;
        private PsychSurvey.Study _study = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString[StudyQueryString] != null)
            {
                _StudyGuid = new Guid(Request.QueryString[StudyQueryString]);
            }
            if (Request.QueryString[DevelopmentQueryString] != null)
            {
                _isDevelopment = true;
            }
            BindStudyData();
            BindAccountUrl();
        }
        private void BindAccountUrl()
        {
#if (DEBUG)
            //hlLink.NavigateUrl = Settings.Default.CreateUserAccount_local;
#else
            //hlLink.NavigateUrl = Settings.Default.CreateUserAccount;
#endif
        }
        private void BindStudyData()
        {            
            dbDataContext db = new dbDataContext();
            _study = db.Studies.Single(x => x.StudyId == _StudyGuid);
            lblStudyTitle.Text = _study.StudyName;
            this.Title = _study.StudyName;
            lblStudyDescription.Text = _study.StudyDescription;
            if (_isDevelopment == false)
            {
                if (_study.IsOpen)
                {                    
                    imgStatus.ImageUrl = "Style/Images/StudyOpen.png";
                    this.pnlLogin.Visible = true;
                }
                else
                {                    
                    imgStatus.ImageUrl = "Style/Images/StudyClosed.png";
                    this.pnlLogin.Visible = false;
                }
                List<Claim> AllClaims = PsychSurvey.Study.GetClaimsAdded(_StudyGuid);
                //gvClaims.DataSource = AllClaims;
                //gvClaims.DataBind();
            }
            else
            {
                lblStudyStatus.Text = "in Testing mode";
                this.pnlLogin.Visible = true;
            }
            slLogin.InitParameters = "studyId="+_StudyGuid.ToString();
        }        
    }
}
